package com.telsoft.ulti;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;

import com.telsoft.business.ComponentBusiness;
import com.telsoft.business.GroupComponentBusiness;
import com.telsoft.business.LibraryBusiness;
import com.telsoft.entity.ComponentEntity;
import com.telsoft.entity.GroupComponentEntity;
import com.telsoft.entity.LibraryEntity;

@SuppressWarnings("serial")
@ManagedBean(name = "treeNode")
@ViewScoped
public class LeftProcess implements Serializable {

    private TreeNode root;
    private List<LibraryEntity> librarys;

    public LeftProcess() {
        root = new DefaultTreeNode(root, null);
        try {
            librarys = LibraryBusiness.getLibrary();
            List<GroupComponentEntity> grComs = GroupComponentBusiness.getGRComponent();
            List<ComponentEntity> coms = ComponentBusiness.getComponent();
            for (LibraryEntity item : librarys) {
                TreeNode lib = new DefaultTreeNode(item.getName(), root);
                for (GroupComponentEntity itemGr : grComs) {
                    TreeNode grC = null;
                    if (itemGr.getLibID() == item.getLibID()) {
                        grC = new DefaultTreeNode(itemGr.getName(), lib);
                    }
                    for (ComponentEntity itemC : coms) {
                        if (itemC.getGrComID() == itemGr.getGrComID()) {
                            TreeNode c = new DefaultTreeNode(itemC.getName(), grC);
                        }
                    }
                }
            }

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public TreeNode getRoot() {
        return root;
    }

    public void setRoot(TreeNode root) {
        this.root = root;
    }

    public List<LibraryEntity> getLib() {
        return librarys;
    }

    public void setLib(List<LibraryEntity> lib) {
        this.librarys = lib;
    }
}
